#include "GamApp.h"
GameApp::GameApp()
{
	szAppName = "Test Init Windows";
}

bool GameApp::InitWindow(HINSTANCE _hInstance)
{
	hInstance = _hInstance;
	WNDCLASSEX   wndclassex = {0};
	wndclassex.cbSize        = sizeof(WNDCLASSEX);
	wndclassex.style         = CS_HREDRAW | CS_VREDRAW;
	wndclassex.lpfnWndProc   = WndProc;
	wndclassex.cbClsExtra    = 0;
	wndclassex.cbWndExtra    = 0;
	wndclassex.hInstance     = hInstance;
	wndclassex.hIcon         = NULL;
	wndclassex.hCursor       = LoadCursor (NULL, IDC_ARROW);
	wndclassex.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
	wndclassex.lpszMenuName  = NULL;
	wndclassex.lpszClassName = szAppName;
	wndclassex.hIconSm       = wndclassex.hIcon;

	if (!RegisterClassEx (&wndclassex))
	{
		MessageBox (NULL, TEXT ("RegisterClassEx failed!"), szAppName, MB_ICONERROR);
		return false;
	}

	hwnd = CreateWindowEx (WS_EX_OVERLAPPEDWINDOW, 
		szAppName, 
		TEXT ("Test Init Windows"),
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, 
		CW_USEDEFAULT, 
		800, 
		600, 
		NULL, 
		NULL, 
		hInstance,
		NULL); 

	if(!hwnd)
	{
		MessageBox(NULL, TEXT("Creat WindowEx Failed!!"), szAppName, MB_ICONERROR);
		return false;
	}

	ShowWindow (hwnd, SW_SHOW);
	UpdateWindow (hwnd);

	return true;
}

LRESULT CALLBACK GameApp::WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	case WM_CREATE:
		return (0);

	case WM_DESTROY:
		PostQuitMessage (0);
		return (0);
	}
	return DefWindowProc (hwnd, message, wParam, lParam);
}

void GameApp::Run()
{
	bool done = false;
	while(!done)
	{
		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			if(msg.message == WM_QUIT)
			{
				done = true;

			}
			TranslateMessage (&msg);
			DispatchMessage (&msg);
		}
	}
}